/********************************************************************************
* File Name:	topscore.cpp
* Description:	第14章实例训练
* Reference book:《Linux环境下Qt4图形界面与MySQL编程》，机械工业出版社.2012.1
* E_mail: openlinux2011@gmail.com
*
********************************************************************************/
#include "topscore.h"
#include "ui_topscore.h"
#include <QtSql>
#include <QMessageBox>
#include "database.h"

Topscore::Topscore(QWidget *parent) :
    QDialog(parent),
    ui(new Ui::Topscore)
{
    ui->setupUi(this);
    if(!database::Open())
    {
        QMessageBox::about(this,"Message","connect error");
        return;
    }
    modelScore=new QSqlTableModel(this);
    modelScore->setTable("list");
    modelScore->select();

    //获取当前列 的索引
    modelScore->setHeaderData(0,Qt::Horizontal,tr("ID"));
    modelScore->setHeaderData(1,Qt::Horizontal,tr("Name"));
    modelScore->setHeaderData(2,Qt::Horizontal,tr("Score"));
    ui->tvList->setModel(modelScore);
    ui->tvList->sortByColumn(2);
    database::Close();
}

Topscore::~Topscore()
{
    delete ui;
}
